package cn.kgc.vue.controller;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Course;
import cn.kgc.vue.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/7/9
 * @description
 */
@RestController
@RequestMapping("course")
@Api(tags = "课程模块")
public class CourseController {

    @Resource
    private CourseService courseService;

    @ApiOperation("课程列表")
    @GetMapping("list")
    public ResponseResult courseList(){

        List<Course> list = courseService.courseList();
        return  ResponseResult.success().data("courseList",list);

    }

    @ApiOperation("课程分页")
    @PostMapping("page")
    public ResponseResult coursePage(@RequestBody QueryCondition<Course> queryCondition){

        return  courseService.coursePage(queryCondition);
    }


    @ApiOperation("新增/编辑课程")
    @PostMapping("addOrUpdate")
    public ResponseResult addOrUpdateCourse(@RequestBody Course course){

        boolean b = courseService.saveOrUpdate(course);

        return  b ?  ResponseResult.success():ResponseResult.fail();
    }

    @ApiOperation("删除课程")
    @DeleteMapping("delete/{id}")
    public ResponseResult deleteCourse(@PathVariable("id") Integer id){

        courseService.removeById(id);

        return  ResponseResult.success().message("删除成功") ;
    }
}
